import type { listData } from '@/services/my'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfoAPI } from '@/services/my'
import type { confirmData } from '@/services/my'
// 手机认证图标
import phoneIcon from '@/static/My/MobileAuthentication.png'
// 实名认证图标
import RealName from '@/static/My/RealNameAuthentication.png'
// 学历认证图标
import education from '@/static/My/Education.png'
// 购车认证图标
import CarBuying from '@/static/My/CarBuying.png'
// 住房认证图标
import walletIcon from '@/static/My/HousingCertification.png'
// 收入认证图标
import incomeIcon from '@/static/My/HousingCertification.png'
// 定义 Store
export const useUserComfirmInfo = defineStore(
    'userInfo',
    () => {
        //获取用户认证信息
        let getUserInfo = () => {
            //发送请求
            getUserInfoAPI(id.value).then((res) => {
                confirmList.value = res.result as confirmData
                phone.value = (res.result as { phone: string }).phone
                list.value.map((item, index) => {
                    item.flag = res.flagList![index]
                })
            })
        }
        //用户信息
        const phone = ref<string>('13111691135')
        const id = ref<string>('1')
        let cache = ref(false)
        const list = ref<listData[]>([
            {
                url: phoneIcon,
                text: '手机认证',
                path: '/pages/my/phoneConfirm/phoneConfirm',
            },
            {
                url: RealName,
                text: '实名认证',
                path: '/pages/my/realIdentityConfirm/realIdentityConfirm',
            },
            {
                url: education,
                text: '学历认证',
                path: '/pages/my/degreeConfirm/degreeConfirm',
            },
            {
                url: CarBuying,
                text: '购车认证',
                path: '/pages/my/carConfirm/carConfirm',
            },
            {
                url: walletIcon,
                text: '住房认证',
                path: '/pages/my/houseConfirm/houseConfirm',
            },
            {
                url: incomeIcon,
                text: '收入认证',
                path: '/pages/my/salaryConfirm/salaryConfirm',
            },
        ])
        const confirmList = ref<confirmData>({})
        // 记得 return
        return {
            list, phone, id, cache, getUserInfo, confirmList
        }
    },
    // TODO: 持久化
    {
        persist: true,
    },
)
